﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;
using Volo.Abp.Domain.Values;

namespace Mozhi.Abp.Domain.BasicData
{
    public class Currency : ValueObject
    {
        [JsonProperty]
        public virtual Guid Id { get; protected set; }

        [JsonProperty]
        public virtual string Code { get; protected set; }

        [JsonProperty]
        public virtual string Name { get; protected set; }

        [JsonProperty]
        public virtual decimal ExchangeRate {  get; protected set; }

        [JsonProperty]
        public virtual bool Activated { get; protected set; }

        public virtual void Validate()
        {
            if (!Activated)
                throw new UserFriendlyException($"货币:{Code}-{Name}已禁用", "100000");
        }

        public virtual void SetExchangeRate(decimal rate)
        {
            ExchangeRate = rate;

            if (ExchangeRate == 0)
                throw new UserFriendlyException($"汇率必须大于0", "100000");
        }

        protected override IEnumerable<object> GetAtomicValues()
        {
            throw new NotImplementedException();
        }
    }
}
